package util;

import java.util.Collection;

import exception.InvalidBusinessStateException;

public class CheckParameters {
	public static void checkStringEmpty(String s, String label) throws InvalidBusinessStateException {
		checkNull(s, label);
		if (s.trim().equals("")) throw new InvalidBusinessStateException(label+" cannot be empty");
	}
	
	public static void checkNull(Object o, String label) throws InvalidBusinessStateException {
		if (o == null) throw new InvalidBusinessStateException("Object "+label+" must be set");
	}
	
	public static void checkPositiveOrZero(double i, String label) throws InvalidBusinessStateException {
		if (i < 0) throw new InvalidBusinessStateException("Number "+label+" cannot be negative ("+i+")");
	}
	
	public static void checkNotZero(double i, String label) throws InvalidBusinessStateException {
		if (i == 0) throw new InvalidBusinessStateException("Number "+label+" cannot be 0");
	}
	
	public static void checkPositive(double i, String label) throws InvalidBusinessStateException {
		if (i <= 0) throw new InvalidBusinessStateException("Number "+label+" cannot be negative or 0 ("+i+")");
	}
	
	public static void checkNotEmptyCollection(Collection<?> collection, String label) throws InvalidBusinessStateException {
		checkNull(collection, label);
		if (collection.size() == 0) throw new InvalidBusinessStateException("Collection "+label+" cannot be empty");
	}
}
